package com.renjian.spring.day06.service;

import com.renjian.spring.day06.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(timeout = -1,propagation = Propagation.REQUIRED,isolation = Isolation.REPEATABLE_READ)
public class UserService {

    //注入daod
    @Autowired
    private UserDao userDao;
    public void accountMoney(){
//       try{

           //1.开启事务
           //renjian少100；
               userDao.reduceMoney();

           //2.执行业务逻辑

           //模拟异常
//           int i=10/0;

           //zhang多100；
           userDao.addMoney();

           //没有异常，提交事务

//       }catch (Exception e){

           //4.出现异常，事务回滚

//       }
    }
}
